package o;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean.a;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.externalapi.view.ThirdApiActivity;
import com.huawei.fastengine.fastview.download.utils.PackageUtils;
import o.dky.j;

public class dgw implements IServerCallBack {
    private IServerCallBack ˋ;
    private Activity ˎ;
    private dgv ˏ;
    private c ॱ;

    public enum c {
        INVOKESTORE4APPLIST,
        INVOKE
    }

    public dgw(Activity activity, c cVar, IServerCallBack iServerCallBack, dgv o_dgv) {
        this.ˎ = activity;
        this.ˋ = iServerCallBack;
        this.ॱ = cVar;
        this.ˏ = o_dgv;
    }

    public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        if (this.ˋ != null) {
            this.ˋ.prePostResult(o_cvu, responseBean);
        }
    }

    public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
        if ((o_cvu instanceof cvv) && (responseBean instanceof StartupResponse)) {
            cvv o_cvv = (cvv) o_cvu;
            StartupResponse startupResponse = (StartupResponse) responseBean;
            if (startupResponse.getResponseCode() == 0 && startupResponse.ॱᐝ() != null && startupResponse.getResponseType() != a.FROM_CACHE && o_cvv.ˏ() == 1) {
                startupResponse.ˎ(o_cvv);
                Object obj = null;
                if (!TextUtils.isEmpty(startupResponse.ॱᐝ())) {
                    Logger.ˎ("GLOBAL_START_FLOW", "StartupCallback getServiceZone" + startupResponse.ॱᐝ());
                    if (!eqp.ॱ().equals(startupResponse.ॱᐝ())) {
                        obj = 1;
                    }
                    String lastHomeCountry = UserSession.getInstance().getLastHomeCountry();
                    if (!(dof.ˋ(lastHomeCountry) || lastHomeCountry.equals(startupResponse.ॱᐝ()))) {
                        obj = 1;
                    }
                    epr.ˎ().ˋ(startupResponse.ॱᐝ());
                }
                if (obj != null) {
                    ˋ(this.ˎ, o_cvv, startupResponse);
                    return;
                } else {
                    ˏ(o_cvv, startupResponse);
                    return;
                }
            }
        }
        if (this.ˋ != null) {
            this.ˋ.notifyResult(o_cvu, responseBean);
        }
    }

    public void ˏ(final cvv o_cvv, StartupResponse startupResponse) {
        eqm ˊ = eqk.ˊ();
        if (ˊ == null) {
            Logger.e("GLOBAL_START_FLOW", "StartupCallback grs == null");
            this.ˋ.notifyResult(o_cvv, startupResponse);
            return;
        }
        ˊ.ॱ(new eql(this) {
            final /* synthetic */ dgw ˊ;

            public void ˋ() {
                this.ˊ.ˎ(o_cvv);
            }

            public void ˎ(int i) {
                Logger.e("GLOBAL_START_FLOW", "StartupCallback grs failed");
            }
        });
    }

    private void ˊ(final boolean z, final cvv o_cvv, final StartupResponse startupResponse) {
        Logger.ˎ("GLOBAL_START_FLOW", "StartupCallback showProtocol");
        diu.ˊ().ॱ(this.ˎ, new o.dio.c(this) {
            final /* synthetic */ dgw ˎ;

            public void ॱ(boolean z) {
                if (z) {
                    this.ˎ.ॱ(z, o_cvv, startupResponse);
                } else if (this.ˎ.ˏ != null) {
                    this.ˎ.ˏ.ˎ();
                }
            }
        });
    }

    private void ˎ(cvv o_cvv) {
        Logger.ˎ("GLOBAL_START_FLOW", "StartupCallback recallStartUpRequest");
        if (!PackageUtils.HWGAMEBOX_PACKAGE_NAME.equals(ContentManager.getInstant().getContext().getPackageName())) {
            String ॱ = eqp.ॱ();
            Logger.ˎ("GLOBAL_START_FLOW", "StartupCallback, getHomeCountry(): " + ॱ);
            o_cvv.ˋ(ॱ);
            o_cvv.ʼ(0);
        }
        switch (this.ॱ) {
            case INVOKESTORE4APPLIST:
                cfw.ˊ((cvt) o_cvv, (IServerCallBack) this);
                return;
            case INVOKE:
                cfw.ˎ(o_cvv, this);
                return;
            default:
                return;
        }
    }

    private void ˊ() {
        if (this.ˎ.getRequestedOrientation() == -1) {
            try {
                this.ˎ.setRequestedOrientation(ˋ());
            } catch (Throwable e) {
                Logger.ˋ("GLOBAL_START_FLOW", " Exception.", e);
            }
        }
    }

    private int ˋ() {
        int i = this.ˎ.getResources().getConfiguration().orientation;
        if (1 == i) {
            return 1;
        }
        return 2 == i ? 0 : -1;
    }

    private void ˋ(Context context, final cvv o_cvv, final StartupResponse startupResponse) {
        Logger.ˎ("GLOBAL_START_FLOW", "StartupCallback showChangDlg");
        if ("com.huawei.appmarket.MainActivity".equals(this.ˎ.getClass().getName())) {
            ˊ();
        }
        dgh.ˏ();
        diu.ˊ().ॱ();
        duj.ˏ().ˎ(duo.class, new Object[0]);
        egv.ॱᐝ().ˏॱ();
        dvt.ˏ().ˋ(1);
        dhq.ॱ().ˊ();
        euf.ˎ().ॱॱ();
        String ˊ = eqp.ˊ();
        ceo.ˎ().ˋ();
        cfw.ˋ();
        new DialogActivity.a(context, "HomeCountryChangeDialog").ॱ(context.getString(j.ˏˎ, new Object[]{ˊ})).ˊ(-2, 8).ˏ(new ckh.a(this) {
            final /* synthetic */ dgw ˋ;

            public void ˏ(AlertDialog alertDialog, DialogActivity.a aVar, int i) {
                this.ˋ.ˊ(this.ˋ.ˎ instanceof ThirdApiActivity, o_cvv, startupResponse);
            }
        }).ˋ(-1, j.ˊॱ).ॱ(false).ˎ();
    }

    void ॱ(boolean z, cvv o_cvv, StartupResponse startupResponse) {
        if (z) {
            egv.ॱᐝ().ˋ();
        }
        ˏ(o_cvv, startupResponse);
    }
}
